package com.aprivate.kn.ratingsystem.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aprivate.kn.ratingsystem.R;
import com.aprivate.kn.ratingsystem.bean.ProjectUsersBean;
import com.aprivate.kn.ratingsystem.util.StringUtilsKt;

public class AuditingStaffView extends LinearLayout {
    private TextView title;
    private EditText auditingName;
    private EditText auditingAddress;
    private EditText auditingPhone;
    private EditText auditingEmail;
    private ImageView auditingDelete;
    private int type;

    public AuditingStaffView(Context context) {
        super(context);
        initView(context);
    }

    public AuditingStaffView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public AuditingStaffView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    public AuditingStaffView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initView(context);
    }

    private void initView(Context context) {
        LayoutInflater.from(context).inflate(R.layout.item_auditing, this, true);
        auditingName = findViewById(R.id.et_byAuditingStaffName);
        auditingAddress = findViewById(R.id.et_byAuditingStaffAddress);
        auditingPhone = findViewById(R.id.et_byAuditingStaffPhone);
        auditingEmail = findViewById(R.id.et_byAuditingStaffEmail);
        auditingDelete = findViewById(R.id.iv_byAuditingStaffDelete);
        auditingDelete.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                removeView(AuditingStaffView.this);
            }
        });
        title = findViewById(R.id.tv_title);
    }

    public void setTitle(String title) {
        this.title.setText(title);
    }

    public String getAuditingName() {
        return String.valueOf(auditingName.getText());
    }

    public void setAuditingName(String auditingName) {
        this.auditingName.setText(auditingName);
    }

    public String getAuditingAddress() {
        return String.valueOf(auditingAddress.getText());
    }

    public void setAuditingAddress(String auditingAddress) {
        this.auditingAddress.setText(auditingAddress);
    }

    public String getAuditingPhone() {
        return String.valueOf(auditingPhone.getText());
    }

    public void setAuditingPhone(String auditingPhone) {
        this.auditingPhone.setText(auditingPhone);
    }

    public String getAuditingEmail() {
        return String.valueOf(auditingEmail.getText());
    }

    public void setAuditingEmail(String auditingEmail) {
        this.auditingEmail.setText(auditingEmail);
    }

    public void setType(int type) {
        this.type = type;
        if (null != title) {
            title.setText(type == 2 ? "审核人" : "受访人");
        }
    }

    public void refreshStaffData(ProjectUsersBean usersBean) {
        if (null == usersBean) {
            return;
        }
        setAuditingName(StringUtilsKt.getString(usersBean.name));
        setAuditingAddress(StringUtilsKt.getString(usersBean.addressOrPosition));
        setAuditingEmail(StringUtilsKt.getString(usersBean.email));
        setAuditingPhone(StringUtilsKt.getString(usersBean.phone));
    }

    public int getType() {
        return type;
    }
}
